﻿using DTcms.Cache.Factory;
using DTcms.Common;

namespace DTcms.BLL
{
    public partial class sitemapconfig
    {
        private readonly DAL.sitemapconfig dal = new DAL.sitemapconfig();
        //缓存关键词及名称
        private const int cacheTime = 30;  //分钟
        private const string cacheString = "dt_cache_sitemap_config";

        /// <summary>
        ///  读取配置文件
        ///  <param name="isCache">是否读取缓存</param>
        /// </summary>
        public Model.sitemapconfig loadConfig(bool isCache = true)
        {
            Model.sitemapconfig model = new Model.sitemapconfig();
            if (isCache)
            {
                model = CacheFactory.Cache().GetCache<Model.sitemapconfig>(cacheString);
                if (model == null)
                {
                    model = dal.loadConfig(Utils.GetMapPath("/xmlconfig/sitemap.config"));
                    CacheFactory.Cache().WriteCache(model, cacheString, cacheTime);
                }
            }
            else
            {
                model = dal.loadConfig(Utils.GetMapPath("/xmlconfig/sitemap.config"));
            }
            return model;
        }

        /// <summary>
        ///  保存配置文件
        /// </summary>
        public Model.sitemapconfig saveConifg(Model.sitemapconfig model)
        {
            return dal.saveConifg(model, Utils.GetMapPath("/xmlconfig/sitemap.config"));
        }
    }
}
